﻿<%@ Page Language="C#" AutoEventWireup="true" CodeFile="CreditNote.aspx.cs" Inherits="Main_Reports_Accounts_CreditNote" %>

<%@ Register Src="~/User Controls/PageHeading.ascx" TagName="Heading" TagPrefix="acc" %>
<%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="ajax" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
    <link href="../../../../Styles/accounts.css" rel="stylesheet" type="text/css" />

    <script type="text/javascript">
        function Validation() {
            var flag = true;
            var txtFromdate = document.getElementById("txtFromDate").id;
            var txtTodate = document.getElementById("txtToDate").id;
            if (document.getElementById("txtFromDate").value == '') {
                alert('Specify From date');
                flag = false;
            }
            else if (document.getElementById("txtToDate").value == '') {
                alert('Specify To date');
                flag = false;
            }
            else {
                if (isDate(txtFromdate) && isDate(txtTodate)) {
                    var dateArray = new Array();
                    dateArray = document.getElementById("txtFromDate").value.split("/");
                    var day1 = dateArray[0];
                    var month1 = dateArray[1];
                    var year1 = dateArray[2];
                    dateArray = document.getElementById("txtToDate").value.split("/");
                    var day2 = dateArray[0];
                    var month2 = dateArray[2];
                    var year2 = dateArray[2];

                    if (day1.length < 2) {
                        day1 = '0' + day1;
                    }
                    if (month1.length < 2) {
                        month1 = '0' + month1;
                    }
                    if (day2.length < 2) {
                        day2 = '0' + day2;
                    }
                    if (month2.length < 2) {
                        month2 = '0' + month2;
                    }
                    var date1 = new Date(year1, month1 - 1, day1);
                    var date2 = new Date(year2, month2 - 1, day2);
                    if (date1 > date2) {
                        alert('Date Could Not be less than From Date');
                        document.getElementById(txtFromdate).focus();
                        flag = false;

                    }
                }
                else {
                    flag = false;
                }
            }
            return flag;
        }
        function isDate(txtDateId) {
            // date length should be 10 characters - no more, no less            
            var Ctrl = document.getElementById(txtDateId);
            var txtDate = Ctrl.value;
            var flag = true;

            // extract day, month and year from the txtDate string
            // expected format is dd/mm/yyyy
            var day = '';
            var month = '';
            var year = '';
            var dateArray = new Array();
            var count = 0;
            for (var j = 0; j < txtDate.length; j++) {
                var chara = txtDate.charAt(j);
                if (chara == '/') {
                    count += 1;
                }
            }
            if (count != 2) {
                alert('Invalid date !');
                return false;
            }
            dateArray = txtDate.split("/");


            day = dateArray[0];
            month = dateArray[1];
            year = dateArray[2];


            if (year.length != 4) {
                alert('Invalid date !');
                return false;
            }
            var finYear = document.getElementById("hidFinyear").value;
            if (month >= 4 && year != parseInt(finYear)) {
                alert('Date Should be between 01/04/' + finYear + ' and 31/03/' + (parseInt(finYear) + 1));
                return false;
            }
            else if (month < 4 && year != (parseInt(finYear) + 1)) {
                alert('Date Should be between 01/04/' + finYear + ' and 31/03/' + (parseInt(finYear) + 1));
                return false;
            }



            if (month == 1 || month == 3 || month == 5 || month == 7 || month == 8 || month == 10 || month == 12) {
                if (day > 31) {
                    alert('Date Should not be Greater than 31');
                    Ctrl.focus();
                    flag = false;
                }
            }
            //for have only 30 day
            else if (month == 4 || month == 6 || month == 9 || month == 11) {
                if (day > 30) {
                    alert('Date Should not be Greater than 30');
                    Ctrl.focus();
                    flag = false;
                }
            }
            //for Febuary 
            else if (month == 2) {
                var leap = year % 4;
                if (leap == 0) {
                    if (day > 29) {
                        alert('february have only 29 days');
                        Ctrl.focus();
                        flag = false;
                    }
                }
                else {
                    if (day > 28) {
                        alert('february have only 28 days');
                        Ctrl.focus();
                        flag = false;
                    }
                }
            }
            else if (month > 12) {
                alert('Invalid Date');
                Ctrl.focus();
                flag = false;
            }
            // otherwise return true
            return flag;
        }



        function printPartOfPage() {
        
           
            var printDiv = document.getElementById("divPrint").innerHTML;
            var windowUrl = 'about:blank';
            var uniqueName = new Date();
            var windowName = 'Print' + uniqueName.getTime();
            var printWindow = window.open(windowUrl, windowName, 'left=5000,top=5000,width=0,height=0');
            printWindow.document.write(printDiv);
            printWindow.document.close();
            printWindow.focus();
            printWindow.print();
            printWindow.close();
            return false;
        }      

       
    </script>

</head>
<body>
    <form id="form1" runat="server">
    <div class="divmain">
        <acc:Heading ID="pagehead" runat="server" HeadingText="Credit Note" />
    </div>
     <asp:HiddenField ID="hidFinyear" runat="server" />
    <ajax:ToolkitScriptManager ID="tc1" runat="server">
    </ajax:ToolkitScriptManager>
    <table style="width:96%; margin-left:2%;">
    <tr>
                <td>
                    <asp:HyperLink ID="hpr" runat="server" Text="Change Date" NavigateUrl="#"></asp:HyperLink>
                     &nbsp;<asp:HyperLink ID="hpr1" runat="server" onClick = "return printPartOfPage();" Text="Print" NavigateUrl="#"></asp:HyperLink>
                </td>
            </tr>
    </table>
    <div id="divPrint" >
        <table style="margin-left: 2%;" width="96%">
            
            <tr align="center">
                <td>
                    <asp:Label ID="lblcompname"  Font-Size="Small" runat="server"></asp:Label>
                </td>
            </tr>
            <tr align="center">
                <td>
                    <asp:Label ID="lblheading" runat="server"></asp:Label>
                </td>
            </tr>
            <tr>
                <td style="width: 100%;">
                    <asp:GridView ID="grddisplay" OnRowDataBound="grddisplay_rowdatabound" CssClass="gridview"
                        runat="server" Width="96%" AutoGenerateColumns="False" ShowFooter="True">
                        <Columns>
                            <asp:BoundField HeaderText="Date" DataField="TransactionDate" DataFormatString="{0:dd-MMM-yyyy}" />
                            <asp:BoundField HeaderText="Type" DataField="Name" />
                            <asp:BoundField HeaderText="Vocher No." DataField="TransactionNumber" />
                            <asp:BoundField HeaderText="Particulars" DataField="Particulars" />
                            <asp:BoundField HeaderText="Debit" DataField="Debit" ItemStyle-HorizontalAlign="Right">
                                <ItemStyle HorizontalAlign="Right"></ItemStyle>
                            </asp:BoundField>
                            <asp:BoundField HeaderText="Credit" DataField="Credit" ItemStyle-HorizontalAlign="Right">
                                <ItemStyle HorizontalAlign="Right"></ItemStyle>
                            </asp:BoundField>
                        </Columns>
                        <EmptyDataTemplate>
                            Records not Found !!</EmptyDataTemplate>
                        <EmptyDataRowStyle Font-Bold="true" HorizontalAlign="Center" ForeColor="Red" />
                    </asp:GridView>
                </td>
            </tr>
        </table>
        </div>
        <asp:Panel ID="panel1" Style="display: none;" CssClass="modalPopup"  runat="server"
            Width="200px" Height="120px">
            <table width="100%" style="margin-top: 20px; margin-left: 5%">
                <tr>
                    <td>
                        From:
                    </td>
                    <td>
                        <asp:TextBox ID="txtFromDate" Width="100px" CssClass="input" runat="server"></asp:TextBox>
                    </td>
                </tr>
                <tr>
                    <td>
                        To:
                    </td>
                    <td>
                        <asp:TextBox ID="txtToDate" Width="100px" runat="server" CssClass="input"></asp:TextBox>
                        <br />
                    </td>
                </tr>
                <tr>
                    <td colspan="2" align="center">
                        <asp:Button ID="btnShow" runat="server" CssClass="button" Text="Show" OnClick="btnShow_Click"
                            OnClientClick="return Validation();" />
                        <asp:Button ID="btnCancel" runat="server" Text="Cancel" CssClass="button" />
                    </td>
                </tr>
            </table>
        </asp:Panel>
        <ajax:ModalPopupExtender ID="modalpopup1" runat="server" BackgroundCssClass="modalBackground" PopupControlID="panel1"
            CancelControlID="btnCancel" TargetControlID="hpr">
        </ajax:ModalPopupExtender>
    
    </form>
</body>
</html>
